﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient


''' <summary>
''' Clase de la capa de acceso a datos DAL que implementa el patrón Table Data Gateway para el manejo de la entidad Empleado
''' </summary>
''' <remarks></remarks>
Public Class TDGEmpleado

    Private Shared m_Instance As TDGEmpleado = Nothing


    Public Function Insert(conn As SqlConnection, _
                        Emp_Legajo As Int16, _
                        Emp_NombreAp As String, _
                        Emp_NroInterno As Int16, _
                        Emp_Mail As String, _
                        Dep_Codigo As Int16, _
                        DVH As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.addEmpleado"
        command.Parameters.AddWithValue("@Emp_Legajo", Emp_Legajo)
        command.Parameters.AddWithValue("@Emp_NombreApp", Emp_NombreAp)
        command.Parameters.AddWithValue("@Emp_NroInterno", Emp_NroInterno)
        command.Parameters.AddWithValue("@Emp_Mail", Emp_Mail)
        command.Parameters.AddWithValue("@Dep_Codigo", Dep_Codigo)
        command.Parameters.AddWithValue("@DVH", DVH)


        iRowsAffected = command.ExecuteNonQuery()


        Return iRowsAffected

    End Function

    Public Function Update(conn As SqlConnection, _
                                    Emp_Legajo As Int16, _
                                    Emp_NombreAp As String, _
                                    Emp_NroInterno As Int16, _
                                    Emp_Mail As String, _
                                    Dep_Codigo As Int16, _
                                    DVH As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.updEmpleado"
        command.Parameters.AddWithValue("@Emp_Legajo", Emp_Legajo)
        command.Parameters.AddWithValue("@Emp_NombreApp", Emp_NombreAp)
        command.Parameters.AddWithValue("@Emp_NroInterno", Emp_NroInterno)
        command.Parameters.AddWithValue("@Emp_Mail", Emp_Mail)
        command.Parameters.AddWithValue("@Dep_Codigo", Dep_Codigo)
        command.Parameters.AddWithValue("@DVH", DVH)


        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Delete(conn As SqlConnection, Emp_Legajo As Int16) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "dbo.delEmpleado"
        command.Parameters.AddWithValue("@Emp_Legajo", Emp_Legajo)

        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Find(conn As SqlConnection, Emp_Legajo As Int16) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getEmpleado"
        command.Parameters.AddWithValue("@Emp_Legajo", Emp_Legajo)


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindAll(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getEmpleado_All"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindAll_RRHH(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getEmpleado_RRHH"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Shared ReadOnly Property Instance()
        Get
            If (m_Instance Is Nothing) Then
                m_Instance = New TDGEmpleado()
            End If

            Return m_Instance
        End Get
    End Property

    Private Sub New()

    End Sub

End Class
